package oop.controller.change;

import java.sql.SQLException;
import java.util.Date;

import oop.data.Article;
import oop.data.User;
import oop.db.dao.ChangeDAO;
import oop.db.dao.UserDAO;

public class Change {

	private long id;
	private long userId;
	private Date datetime;
	private String comment;
	private long namespaceId;
	private long articleId;
	private ChangeDelegate delegate;
	private boolean minor;

	public Change(long id, long userId, Date datetime, String comment,
			long namespaceId, long articleId, boolean minor, ChangeDelegate delegate) {
		super();
		this.id = id;
		this.userId = userId;
		this.datetime = datetime;
		this.comment = comment;
		this.namespaceId = namespaceId;
		this.articleId = articleId;
		this.minor = minor;
		this.delegate = delegate;
	}

	public void perform() throws Exception {
		delegate.perform();
	}

	public boolean isReversible() {
		return delegate.isReversible();
	}

	public Change reverse() throws Exception {
		return ChangeDAO.create(userId, datetime, comment,
				namespaceId, articleId, minor, delegate.createReverse());
	}

	public String getSummary() throws Exception {
		return delegate.getSummary();
	}

	public User getUser() throws SQLException {
		return UserDAO.fetchById(userId).get(0);
	}

	public Date getDatetime() {
		return datetime;
	}

	public String getComment() {
		return comment;
	}

	public Article getArticle() {
		return null; // TODO
	}

	public long getId() {
		return id;
	}

	public boolean isMinor() {
		return minor;
	}
	
	public boolean hasDetail() {
		return delegate.hasDetail();
	}

	public String getDetail() {
		return delegate.getDetail();
	}
	
}
